package com.exle.controller;

import java.security.Principal;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.exle.domain.User;
import com.exle.service.UserService;

@Controller
public class BaseController {

	@Autowired
	private UserService userService;

	@RequestMapping(value = "/start", method = RequestMethod.GET)
	public String home(Model model, HttpServletRequest request) {

		return "start";
	}

	@RequestMapping(value = "/admin/home", method = RequestMethod.GET)
	public String admin(Model model, HttpServletRequest request, Principal principal) {
		String current_user = principal.getName();
	
		model.addAttribute("current_user", current_user);
		return "admin/home";
	}

	@RequestMapping(value = "/teacher/home", method = RequestMethod.GET)
	public String teacher(Model model, HttpServletRequest request) {

		return "teacher/home";
	}

	@RequestMapping(value = "/student/home", method = RequestMethod.GET)
	public String student(Model model, HttpServletRequest request) {

		return "student/home";
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(Model model, HttpServletRequest request, Principal principal) {
		String current_user = principal.getName();
		
		model.addAttribute("current_user", current_user);
		List<User> users = userService.getUsers();
		model.addAttribute("users", users);
		return "list";
	}

}
